/**
 * 
 */
var QS_toDate=function(d){
    var d = new Date(d);
    return QS_DateFmt.getWeekDay(d)+' '+QS_DateFmt.getDateString(d);
};
var QS_toTime=function(value){
	if(isNaN(value)){
		return "--";
	}
	var d=new Date();
	var t = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() + parseInt(value) * 1000;
    var dt = new Date(t);
    return (dt == null) ? "--" :QS_DateFmt.getTimeString(dt);
};
var QS_splitDataByLen=function(d,len){
	var sign=d<0?'-':'';
	d=Math.abs(d);
	var dArr = (d + "").split(".");
	var l1 = dArr[0].length;
	dArr[0]=QS_NumFmt.Fmt2(dArr[0],false,"",0);
	if(l1>=len){
		d=dArr[0];
	}else{
		var d2 = parseFloat("0." + dArr[1], 10).toFixed(len - l1);
		dArr[1] = d2.split(".")[1];
		d = dArr.join('.');
	}
	return sign+d;
};
var QS__Formatter=function(d,dataType,secType){
	dataType=typeof dataType=='undefined'?'f':dataType;//if dataType is empty, that means the dataType is a default "float".
    if(typeof d=='undefined'|| d=='--'){
        return '--';
    }
    switch(dataType){
        case 'f2':{
            d = QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d,10).toFixed(2);
            break;
        }
        case 'f4':{
            if (Math.abs(d) * 100 < 1 && d != 0) {
                d = QS_NumFmt.Fmt2(d,false,"",4);//parseFloat(d, 10).toFixed(4);
            }else {
                d = QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d, 10).toFixed(2);
            }
            break;
        }
        case 'i':
		    d = QS_NumFmt.Fmt2(d,false,"",0); 
			break; 
        case 's':{
            break;
        }
        case 'sf':{
			if(secType=='20'){
				d=QS_splitDataByLen(d,5);
			}else{
				d = QS_NumFmt.Fmt2(d,false,"",2);
			}
            break;
        }
        case 'd':{
            d = QS_toDate(d.replace(/-/g,'/'));
            break;
        }
        case 't':{
            d = QS_toTime(d);
            break;
        }
        case 'm':{
			d=QS_NumFmt.Fmt2(d,true," ",2);
			/*
            d=parseInt(d,10);
            if(d>100000){
                d=(d/1000000).toFixed(1)+' mil';
            }*/
            break;
        }
        case '%':{
            d=QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d,10).toFixed(2)+'%';
            break;
        }
        case 'dm':{
			d=QS_NumFmt.Fmt2(d*1000000,true," ",2);
            /*d=parseFloat(d,10);
            if(d>1000){
                d=(d/1000).toFixed(1)+' bil';
            }else{
                d=d.toFixed(1)+' mil';
            }*/
            break;
        }
        case 'star':{
            d = '<span class="star'+d+'"></span>';
            break;
        }
        case 'sty':{
            d = '<span class="sty'+d+'"></span>';
            break;
        }
        case 'exch':{
        	gExchangeMap=QSAPI.DataManager._getExchangeMap();
           d = typeof d=='undefined'||!gExchangeMap[d]?"--":gExchangeMap[d];
            break;
        }
        case 'cat':{
            var a = d.split(' ');                 
            a.splice(0,1);
            d = a.join(' ');
            break;
        }
        default:{
            if(!isNaN(d)){
				d=QS_NumFmt.Fmt2(d,true," ",2);
                /*d=parseFloat(d,10);
                if(d>100000000){
                    d=(d/1000000000).toFixed(1)+' bil';
                }
                else if(d>100000){
                    d=(d/1000000).toFixed(1)+' mil';
                }else{
                    d=d.toFixed(2);
                }*/
            }
            break;
        }
    }
    return d;
};
var QS_Formatter=function(gkey,field,dataType){
    var d=typeof gkey=='undefined'?{}:(typeof gData[gkey]=='undefined'?{}:gData[gkey]);
    var marketQuoteData=(typeof gkey=='undefined'||gkey==null)?{}:QSAPI.DataManager._getData(gkey);
    var secType=typeof d['type']=='undefined'?-1:d['type'];
    if(field.length==2){
        var val1,val2;
        if(typeof marketQuoteData[field[0]]!='undefined'){
            val1=marketQuoteData[field[0]].value;
        }else{
			val1=d[field[0]];
		}
        if(typeof marketQuoteData[field[1]]!='undefined'){
            val2=marketQuoteData[field[1]].value;
        }else{
			val2=d[field[1]];
		}
        return QS__Formatter(val1,dataType,secType)+"-"+QS__Formatter(val2,dataType,secType);
    }else{
        var val1;
        if(typeof marketQuoteData[field[0]]!='undefined'){
            val1=marketQuoteData[field[0]].value;
        }else{
			val1=d[field[0]];
		}
        return QS__Formatter(val1,dataType,secType);
    }
};

if(!QS){
    var QS={};
}
if (!QSAPI){
	var QSAPI={};
}

QSAPI.SettingPanelContianer=function(container,domObj,profile,callbacks){
	var t=QS_Lang.quote;
	this.HTML='<div class="qs-ui-setpn hide">'+
              '<div class="hd settinghd"><h3>'+t.settings+'</h3><a href="" class="qs-ui-close">x</a></div>'+
              '<div class="bd settingbd"></div>'+
              '<div class="ft"></div>'+
              '</div>';
	this.el=null;
	this.profile={};
	this.visible=false;
	if(profile) {
        $.extend(this.profile,profile);
    }
	this.callbacks=callbacks||{}; 
	this.anacliticObject=null;
	this.init(container,domObj);
};
QSAPI.SettingPanelContianer.prototype={
	init:function(container,domObj){
		this.el=$(this.HTML);
		this.closeBtn=this.el.find('.qs-ui-close');
		this.elBody=this.el.find('.bd');
		this.el.appendTo(container||$('body'));
		this.anacliticObject=container.find('.qs-ui-btn.setting.quote-setting');
		if(domObj){
			this._appendDom(domObj);
		}
		this.closeBtn.bind('click',this,function(e){
			e.preventDefault();
			var self = e.data;
            self.hide();
		});
	},
	_appendDom:function(domObj){
		this.elBody.append(domObj);
	},
	getVisible:function(){
		return this.visible;
	},
	getDom:function(){
		return this.elBody;
	},
	show:function(){			
		this.el[0].className='qs-ui-setpn';
		if(typeof(this.callbacks.onShow)== "function"){
            this.callbacks.onShow(this.elBody);
        }
		this.visible=true;
	},
	hide:function(){
        this.el[0].className='qs-ui-setpn hide';
		if(typeof(this.callbacks.onHide)== "function"){
            this.callbacks.onHide(this.elBody);
        }
		this.visible=false;
	},
	toggle:function(){
		var clsName=this.el[0].className;
		if(clsName=='qs-ui-setpn'){
			this.hide();
		}else{
			this.show();
		}
	},
    resize:function(w,h){
        w=w>0?w:this.width;
        h=h>0?h:this.height;
        if(w!=this.width){
            this.width=w;
        }
        if(h!=this.height){
            this.height=h;
        }
        this.el.width(w);
        this.el.height(h);
    }		
};

QSAPI.QuoteHead=function(container,option,callback){
    this.html=null;//
    this.el=null;
    this.nameEl=null;
    this.symbolEl=null;
	this.secTypeEl=null;
    this.option={
		isFormatName:true,
		showSecType:false
	};
    this.callback={};
    if (option) {
       $.extend(this.option,option)
    }
    if (callback) {
       $.extend(this.callback,callback)
    }
    this.container=container;
    this.init();
};
QSAPI.QuoteHead.prototype={
    init:function(){
		this.html='<div class="rtq-quotes-hd"><div class="name-symbol"><h1 class="name"></h1><span class="symbol"></span></div>'+(this.option.showSecType?'<span class="sectype"></span>':'')+'</div>';
        this.el=$(this.html).appendTo(this.container);
        this.nameEl=this.el.find('.name');
        this.symbolEl=this.el.find('.symbol');
		if(this.option.showSecType){
			this.secTypeEl=this.el.find('.sectype');
		}
    },      
    getHeight:function(){
        return this.el.outerHeight(true);
    },
    changeInfo:function(info){
		var name=info.companyName;
		if(this.option.isFormatName&&name!=""){
			name=info.companyName;
		}
		this.nameEl[0].innerHTML=name;
		if(info.companyName!=info.symbol){
			this.symbolEl[0].innerHTML=info.symbol;
		}
		if(this.secTypeEl!=null&&info.secType!=""){
			var t=QS_Lang.quote;
			this.secTypeEl[0].innerHTML=t["sectype"+info.secType.toLowerCase()]||'';
		}
    },
    show:function(){
        this.el.show();
    },
    hide:function(){
        this.el.hide();
    },
    clear:function(){
    	if (this.quote_setting){
    		this.quote_setting.clear();
    	}    	
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};
QSAPI.QuoteUnique=function(container,option,callback){
    this.el=null;
	this.priceEl=null;
	this.changeEl=null;
	this.changeElOutWidth=null;
	this.changeDomPaddingWidth=0;
    this.option={
		showNewsLink:false,
		showCurrency:true,
		showTimeZone:false,
		showExtendHour:true,
		showRorD:true
	};
    this.callback={};
    this.domMap={};
    this.dpfMap={};
    this.html=null;
    this.dataPoints=null;
    this.width=0;
    this.height=0;
    this.container=container;
    if(option){
        $.extend(this.option,option);
    }
    if(callback){
        $.extend(this.callback,callback);
    }
    this.init();
};
QSAPI.QuoteUnique.prototype={
    init:function(){
        var self=this;
        this.dataPoints=this.buildDataPoints();
        this.html=this.buildInnerHTML();
        this.el=$(this.html).appendTo(this.container);
        var d;
        for(var i=0,l=this.dataPoints.length;i<l;i++){
            d=this.dataPoints[i];
			if(d==null||d.isStatic)continue;
            this.domMap[d.val]=this.el.find('span[domid="'+d.val+'"]')[0];
            this.dpfMap[d.val]=d.dataType;
        }
        this.chgPDom=$(this.domMap['Chg']).closest('div')[0];
        this.domMap['Chg%']=this.el.find('span[domid="Chg"]')[1];
        this.dpfMap['Chg%']=this.dpfMap['Chg'];
        this.LastPriceTxtDom=this.el.find('.cx .lastText');
		this.priceEl=this.el.find('.cx').eq(0);
		this.changeEl=this.el.find('.cx').eq(1);
		this._initVauleForIE7();
        this.container.css({width:this.getWidth(),height:this.getHeight()});
        if (this.option.showNewsLink) {
            this.el.find('span[domid="news"]').bind('click.quoteUnique',function(){
                if(typeof self.callback.onNewsClick=='function'){
                    self.callback.onNewsClick('All');
                }
            });
        }
    },
	_initVauleForIE7:function(){
		if($.browser.msie && parseInt($.browser.version) < 8){
			this.changeChildrenEl=this.changeEl.find('.chg').children();
			this.changeDomPaddingWidth=this.changeEl.outerWidth(true)-this.changeEl.width();//get changel padding,border and margin width
		}
	},
    buildInnerHTML:function(){
        var html='<div class="qs-quote-unique clearfix">',d;
        for(var i=0,l=this.dataPoints.length;i<l;i++){
            var d=this.dataPoints[i];
			if(d==null){
				continue;
			}
            var valTxt=d.valTxt||'--';
            if(d.val=='Chg'){
                html += '<div class="' + d.cls + '"><div><span class="rtq-tt '+(d.tCls?d.tCls:'')+'">' + d.txt + '</span></div><div class="chg"><span class="rtq-d change ' + (d.vCls?d.vCls:'') + '" domid="' + d.val + '">'+valTxt+'</span><span class="rtq-d changep ' + d.vCls + '" domid="' + d.val + '">'+valTxt+'</span><sup>%</sup></div></div>';
            }else{
                html +='<div class="'+d.cls+'"><div><span class="rtq-tt '+(d.tCls?d.tCls:'')+'">'+d.txt+'</span></div><div><span class="rtq-d '+(d.vCls?d.vCls:'')+'" domid="'+d.val+'">'+ valTxt +'</span></div></div>';
            }
        }
        html+='</div>';
        return html;
    },
    buildDataPoints:function(){
		var t=QS_Lang.quote;
         return [{val:'LastPrice',txt:t.lastprice,cls:'cx',tCls:'lastText',dataType:'sf',vCls:'big'},// 'sf' decimals by sec type
        {val:'Chg',txt:t.daychange,cls:'cx',dataType:'sf',vCls:'big'},
        //{val:'Chg%',txt:'Day Change',cls:'cx',dataType:'f',dataFormat:'#.0000',vCls:'big'},
        {val:'AfterTxt',txt:'',cls:'afd',dataType:'s'},
        this.option.showExtendHour?{val:'Date',txt:'',cls:'aft',dataType:'d'}:{val:'TradeDate',txt:'',cls:'aft',dataType:'d'},
        this.option.showExtendHour?{val:'Time',txt:'',cls:'aft',dataType:'t'}:{val:'TradeTime',txt:'',cls:'aft',dataType:'t'},
		this.option.showTimeZone?{val:'TimeZone',txt:'',cls:'aft',dataType:'s',valTxt:'GMT',isStatic:true}:null,
        this.option.showCurrency?{val:'currency',txt:'',cls:'cur',dataType:'s'}:null,
        this.option.showRorD?{val:'R/D',txt:'',cls:'cur',dataType:'s'}:null,
        this.option.showNewsLink?{val:'news',txt:'',cls:'newslink',dataType:'s',valTxt:t.news,isStatic:true}:null]
    },
    changeLastText:function(lastText){
        this.LastPriceTxtDom[0].innerHTML=lastText;
    },
    getWidth:function(){
        if (this.width == 0) {
            this.width = this.el.outerWidth(true);
        }
        return this.width;
    },
    getHeight:function(){
        if(this.height==0){
            this.height=this.el.outerHeight(true);
        }
        return this.height; 
    },
    updateData:function(gkey,data){
		var d=typeof gkey=='undefined'?{}:(typeof gData[gkey]=='undefined'?{}:gData[gkey]);
		var marketQuoteData=(typeof gkey=='undefined'||gkey==null)?{}:QSAPI.DataManager._getData(gkey);
		var secType=typeof d['type']=='undefined'?-1:d['type'];
        var el;
        for(var field in data){
            el=this.domMap[field];
            if(el){
				var originalValue=typeof marketQuoteData[field]!='undefined'?marketQuoteData[field].value:d[field];
				if(field=='Chg'){
                    this._setColorForChg(originalValue||'--',this.chgPDom);
					if(!isNaN(originalValue)){
						originalValue= Math.abs(originalValue);//change value need positive 
					}
                }
				var formatValue=QS__Formatter(originalValue,this.dpfMap[field],secType);
                el.innerHTML=formatValue;
                //console.log(el.outerHTML);
            }
        }
        if(!this.option.showExtendHour||(this.domMap['AfterTxt']&&(!gData[gkey]||gData[gkey].showAfter==0||typeof gData[gkey].showAfter=='undefined'))){
            this.domMap['AfterTxt'].innerHTML='';
        }
        
    },
    _setColorForChg:function(value,dom){
        if(value>0&&dom.className!='chg rise'){
            dom.className='chg rise';
            dom.style.color=QS_Style.greenFontColor;
        }else if(value<0&&dom.className!='chg down'){
            dom.className='chg down';
            dom.style.color=QS_Style.redFontColor;
        }else if((value==0||value=='--')&&dom.className!='chg'){
            dom.className='chg';
            dom.style.color='';
        }
    },
	_getChangeWidth:function(){		
		if($.browser.msie && parseInt($.browser.version) < 8){//if browser version is IE7
			var w=0,self=this;
			$.each(this.changeChildrenEl,function(i){
				w+=self.changeChildrenEl.eq(i).outerWidth(true);
			})
			return w+this.changeDomPaddingWidth;
		}else{
			return this.changeEl.outerWidth(true);
		}
	},
    changeWidth:function(data){
        if(typeof data['LastPrice']=='undefined'&&typeof data['Chg']=='undefined'){
            return;
        }
        var w=this.priceEl.outerWidth(true)+this._getChangeWidth()+10;
        if(this.width<w){// if current width< dom width, need add as a logic.
            var n=Math.ceil((w-this.width)/90);
            this.width=this.width+90*n;
            this.el.width(this.width);
            if(typeof this.callback.onWidthChange=='function'){
                this.callback.onWidthChange(this.width);
            }
            //this.container.width(this.width); 
        }
    },
    clear:function(){
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};

QSAPI.BaseQuote={
	    html:'<div class="rtq-quotes"><div class="quote-head-container"></div><div class="quote-grid-container"></div></div>',
	    el:null,
	    grid:null,
	    gKey:null,
	    head:null,
	    dataScrollPN:null,
	    //domMap:{is:'rw',init:{}},
	    dpfMap:null,
	    quoteUnique:null,
	    level2El:null,
	    //monitorUnqiueWidth:{is:'rw',init:false},
	    dataPoints:[],
	    //dataFormatMap:null,
	    lastCallbackHeight:0,
	    minWidth:460,
	    minHeight:50,
	    loaded:false,
	    defaultConfig:{
	        fixHeight:true,
	        showHead:true,
	        hasUnqiue:true,
	        rowRemoveable:true,
	        rowDragable:true,
	        rowDropable:true,
	        groupDragable:false,
	        groupDropable:false
	    },
	    sequence:[],
	    container:null,
	    parent:null,
	    /**Methods*/
	    setParent:function(parent){
	    	this.parent=parent;
	    },
	    setGKey:function(gKey){
	        this.gKey=gKey;
	    },
	    setDataPoints:function(dps){
			var arr=[]; 
			if(this.option.licencesDataPoints){// remove the license datapoints
				for(var i=0,l=dps.length;i<l;i++){
					if(!this.option.licencesDataPoints[dps[i].val]){
						arr.push(dps[i]);
					}
				}
			}
			if(arr.length>0){
				this.dataPoints=arr;
			}else{
				this.dataPoints=dps;
			}
	        
	    },
	    init:function(){
	        if(typeof this.beforeInit=='function'){
	            this.beforeInit();
	        }
	        if(this.option.sequence){
	            this.sequence=this._convertSequence(this.option.sequence);
	            this.option.sequence=[];//clear the option sequence
	        }
	        this.el=$(this.html).appendTo(this.container);
	        if(this.option.customCls){
	            this.el.addClass(this.option.customCls);
	        }
	        if(this.option.showHead){
	             this.head=new QSAPI.QuoteHead(this.el.find('.quote-head-container'),{isFormatName:this.option.isFormatName,showSecType:this.option.showSecType});
	        }
	        this._createGrid();
	        if (this.option.fixHeight) {
	            this.dataScrollPN = new Util.ScrollPanel(this.el.find('.quote-grid-container'), {});
	        }
	        this.allDataPoint=this.__buildDatapoints(this.gKey,this.sequence);
	        var selectedDataPoints=[];
	        if (this.sequence.length > 0) {
	            for (var i = 0, l = this.sequence.length; i < l; i++) {
	                //if(this.sequence[i]==)
	                for (var j = 0, len = this.dataPoints.length; j < len; j++) {
	                    if (this.dataPoints[j].val == this.sequence[i]) {
	                        selectedDataPoints.push(this.dataPoints[j]);
	                        break;
	                    }
	                }
	            }
	        }else{
	            selectedDataPoints=this.dataPoints;
	        }
	        this.sequence=[];
			this.dpfMap={};
	        this.addDataPoints(selectedDataPoints);
	    },
	    _createGrid:function(){
	        var self=this;
	        var column= [
	            { header: "Val", dataIndex: 'val',width:'100%',height:0,dataType:'string',className:'rtq-qs-hide'},            
	            { header: "Txt", dataIndex: 'txt',width:'100%',height:'50%',dataType:'string',className:'rtq-qs-tt'},                
	            { header: "Data", dataIndex: 'data',width:'100%',height:'50%',dataType:'float'}
	        ];   
	        if(this.option.rowRemoveable){
	            column.push({ header: 'DEL', dataIndex: 'remove', type:'remove', renderer:'<a href="javascript:void(0)">Remove</a>' });
	        }
	        if(this.option.groupable){
	            column.push({ header: "Group", dataIndex: 'group', hide: true});
	        }
	        var option= {            
	            outSideHeader:true,
	            column:column,          
	            indexColKey:'val',
	            //groupDataIndex:'Group',
	            rowLayout:'grid',
	            rowDragable: this.option.rowDragable,
	            rowDropable: this.option.rowDropable,
	            rowDragDropGroup: 'gridQuotes',
	            groupDragable: this.option.groupDragable,
	            groupDropable: this.option.groupDropable,
	            sortDataType: 'float',
	            showYScrollbar:false,
	            autoWidth:true,
	            autoHeight:true     
	        };
	        if(this.option.groupable){
	            option.groupDataIndex=this.option.groupDataIndex;
	        }
	        this.grid=new Util.DataGrid(this.el.find('.quote-grid-container'),[],option, {
	            onRowDragStart: function(e, proxy, row){
	                if (row.id == 'uniquespace'||row.id == 'level2') {//provent to drag the unique
	                    row.dragObj.stop();
	                }else {
	                    proxy.html(row.cells.txt.text);
	                }                
	            },
	            onRowRemove:function(id, row){
	                self._removeSequence(id);
	                if(typeof self.callback.onRemoveRow=='function'){
	                    self.callback.onRemoveRow(id,row);
	                }
					if(self.parent){
						self.parent.__executeCallback('onStateChange');
					}	                
	            },
				onAfterRowRemove:function(id){
					self.changeOutSize(null,null,true);
					if(self.parent){
						self.parent.__executeCallback('onStateChange');
					}
				},
	            beforeGroupDrop:function(proxy, group, toGroup){
	                if (toGroup.value == 'default') {
	                    proxy._stopEvent = true;
	                }
	            },
	            afterGroupDrop:function(proxy, group, toGroup){
//	                  proxy._stopEvent = false;
//	                  self._setComponentContainerPosition();
	            }
	        }); 
	        this.grid.el.addClass('quote-grid');
	        if(this.option.hasUnqiue){
	           var rowData={
	                val:'uniquespace',
	                txt:'',
	                data:'',
	                group:'default'
	            };
	            this.grid.addRow(rowData);
	            var unqiueEl=this.grid.rows['uniquespace'].el.empty().addClass('rtq-grid-row-unique');
	            this.quoteUnique=new QSAPI.QuoteUnique(unqiueEl,{showNewsLink:this.option.showNewsLink,showCurrency:this.option.showCurrency,showTimeZone:this.option.showTimeZone,showExtendHour:this.option.showExtendHour},{
	                onNewsClick:function(sourceCode){
	                    if(typeof self.callback.onClickNewsLink=='function'){
	                        self.callback.onClickNewsLink(self.gKey,sourceCode);
	                    }
	                },
	                onWidthChange:function(w){
	                    unqiueEl.width(w);
	                    if (w > self.option.width) {// force change the width to show the scrollbar
	                        self.grid.el.width(w);
	                        self.changeOutSize(self.option.width,self.option.height,true);
	                    }
	                }
	            });
	        }
	    },
	    removeDataPoints:function(dataPoints){
	    	if (!dataPoints){
	    		return;
	    	}	
            if (!this.dataPoints){
            	return;
            }	    
	    	for (var i = 0, l = dataPoints.length; i < l ; i++) {
	    		 for(var j=0;j<this.dataPoints.length;j++){
	    			 if (dataPoints[i].val==this.dataPoints[j].val){
	    				 this.removeDataPointByVal(dataPoints[i].val);
	    				 this.dataPoints.splice(j,1);
	    				 break;
	    			 }
	    		 }
	    	}
	    	for (var i = 0, l = dataPoints.length; i < l ; i++) {
	    		for(var j=0;j<this.dataPoints.length;j++){
	    			if (dataPoints[i].val==this.sequence[j]){
	    				this.sequence.splice(j,1);
	    				break;
	    			}
	    		}
	    	}
	    },
	    addDataPoints:function(dataPoints){
	    	if (!dataPoints){
	    		return;
	    	}
			var title=QS_Lang.quote;
	        for (var i = 0, l = dataPoints.length; i < l ; i++) {
	           var dataPoint=dataPoints[i];
	            if (dataPoint.val == 'level2') {
	                this.grid.addRow(dataPoint);
	                var level2RowEl=this.grid.rows['level2'].el;
	                level2RowEl.html('').css({
	                    width:'100%',
	                    height:'160px'
	                });
	                this.level2El=$('<div class="rtq-quotes-level2-container clearfix"><div class="comp left"><div class="comp-hd">'+title.level2ts+'</div><div class="comp-bd"></div></div><div class="comp right"><div class="comp-hd">'+title.level2md+'</div><div class="comp-bd"></div></div></div>').appendTo(this.el.find('.quote-grid-container'));
	                this._setComponentContainerPosition();
	            }else {
	                var ndp = {};
	                $.extend(true, ndp, dataPoint);
	                ndp.data = QS_Formatter(this.gKey, ndp.val.split(','), ndp.dataType);
	                var vals = ndp.val.split(',');
	                this.grid.addRow(ndp);
	                if (vals.length == 2) {
	                    this.dpfMap[vals[0]] = this.dpfMap[vals[1]] = {
	                        vals: vals,
	                        dataType: ndp.dataType,
	                        dom: this.grid.DOMMap[ndp.val]['data'],
	                        showHoverTip:ndp.showHoverTip===true?true:false
	                    };
	                }
	                else {
	                    this.dpfMap[dataPoint.val] = {
	                        vals: [ndp.val],
	                        dataType: ndp.dataType,
	                        dom: this.grid.DOMMap[ndp.val]['data'],
							showHoverTip:ndp.showHoverTip===true?true:false
	                    };
	                }
	            }
	            if (!this.dataPoints){
	            	this.dataPoints=[];
	            }
	            this.dataPoints.push(dataPoint);
	            this.sequence.push(dataPoint.val);
	        }
	        //this.changeOutSize();
	    },
	    _setComponentContainerPosition:function(){
	        if(this.hasLevel2Row()){
	            this.level2El.css({
	                top:this.getLevel2Row().el[0].offsetTop,
	                left:0
	            }).show();
	        }
	    },
	    getLevel2Row:function(){
	        return this.grid.rows['level2'];
	    },
	    hasLevel2Row:function(){
	        return !this.grid||typeof this.grid.rows['level2']=='undefined'?false:true;
	    },
	    getLevel2Container:function(){
	        return this.level2El.find('.comp-bd');
	    },
	    changeHeadInfo:function(info){
	        if(this.option.showHead){
	            this.head.changeInfo(info);
	        }
	    },
	    changeUniqueLastText:function(text){
	        if(this.option.hasUnqiue) {
	            this.quoteUnique.changeLastText(text);
	        }
	    },
	    changeOutSize:function(w,h,flag){
	        var parent = this.el.parent();
	        w = w>0?w:parent.width();
	        h = h>0?h:parent.height();
	        var size={width:w};
	        if(this.option.fixHeight){
	            size.height=h;
	        }
	        var self = this;
	        if(this.option.showHead){
	            h=h-this.head.getHeight();
	        }
	        flag=flag===true?true:false;
	        if(w!=this.option.width){
	            this.option.width=w;
	            flag=true;
	        }
	        if(h!=this.option.height){
	            this.option.height=h;
	            flag=true;
	        }
	        if(this.dataScrollPN==null){
	            self._runAfterResize();
	        }else{
	            if(flag){
	                this.dataScrollPN.reSize(w,h, function(){
	                	if (self._runAfterResize){
	                   self._runAfterResize();
	                	}
	                }
	                	
	                );
	            }
	        }
	        this.onHeightChange(this.el.outerHeight(true));
	    },
	    _runAfterResize:function(){
	        this._setComponentContainerPosition();
	        if(typeof this.callback!='undefined'&&typeof this.callback.afterResize=='function'&&this.hasLevel2Row()){
	            var compEl=this.level2El.find('.comp-bd').eq(0);
	            this.callback.afterResize(compEl.width(),compEl.height());
	        }
	    },
	    onHeightChange:function(height){
	        if(height<this.minHeight){
	            height=this.minHeight;
	        }
	        if (!this.loaded) {
	            this.loaded = true;
	            this.lastCallbackHeight = height;
	            if (typeof this.callback.onLoad == 'function') {
	                this.callback.onLoad({
	                    component: 'quote',
	                    height: height,
	                    minWidth:this.minWidth,
	                    minHeight:this.minHeight
	                });
	            }
	        }else {
	            if (this.lastCallbackHeight != height) {
	                this.lastCallbackHeight = height;
	                if (typeof this.callback.onHeightChange == 'function') {
	                    this.callback.onHeightChange({
	                        height: this.lastCallbackHeight,
	                        component: 'quote'
	                    });
	                }
	            }
	        }
	    },
	    addDataPointByVal:function(val){
	        var dp;
	        for(var i=0,l=this.dataPoints.length;i<l;i++){
	            dp=this.dataPoints[i];
	            if(val==dp.val){
	                this.addDataPoints([dp]);
	                this.parent.__addDataPointBySetting(val);
	                
	                break;
	            }
	        }
			this.changeOutSize(null,null,true);
	    },
	    removeDataPointByVal:function(val){
	        if(this._removeSequence(val)){
	            delete this.dpfMap[val];//delete dpf map
	            this.grid.removeRow(val,false);
				this.parent.__removeDataPointBySetting([val]);	            
	        }
			this.changeOutSize(null,null,true);
	    },
	    addAllDataPoints:function(){	
	    	var parent=this.parent;
			this.removeAllDataPoints();
	        this.addDataPoints(this.allDataPoint);
	        for(var i=0,l=this.allDataPoint.length;i<l;i++){
	        	parent.__addDataPointBySetting(this.allDataPoint[i].val);
	        	parent.removeSequenceMap={};
	        }
//			this.changeOutSize(null,null,true);
	        parent.changeOutSize(parent.option.width,parent.option.height,true);
	    },
	    removeAllDataPoints:function(){
	        this.dpfMap={};
	        var parent=this.parent;
	        for(var i=0,l=this.sequence.length;i<l;i++){
	            this.grid.removeRow(this.sequence[i],false);
	            parent.removeSequenceMap[this.sequence[i]]=this.sequence[i];
	        }	        
	        this.sequence=[];
	        this.dataPoints=[];
	        parent.dataPointsPool=[];
//			this.changeOutSize(null,null,true);
	        parent.changeOutSize(parent.option.width,parent.option.height,true);
	    },
	    _removeSequence:function(val){
	        var index=$.inArray(val,this.sequence);
	        if(index>-1){
	            this.sequence.splice(index,1);
	            return true;
	        }
	        return false;
	    },
	    updateData:function(data){
	        var el,udata={};
	        for(var field in data){
	            if (this.option.hasUnqiue && this.quoteUnique.domMap[field]) {
	                udata[field] = true;//QS_Formatter(this.gKey,[field],this.quoteUnique.dpfMap[field]);//data[field];
	            }else {
	                el = this.dpfMap[field]&&this.dpfMap[field].dom?this.dpfMap[field].dom:null;
	                if (el) {
						var formatValue= QS_Formatter(this.gKey,this.dpfMap[field].vals,this.dpfMap[field].dataType);
						if(this.dpfMap[field].showHoverTip){
							formatValue='<a class="hover-cursor" href="javascript:void(0)" title="'+formatValue+'">'+formatValue+'</a>';
						}
	                    el.innerHTML = formatValue;
	                }
	            }
	        }
	        if(this.option.hasUnqiue){
	            this.quoteUnique.updateData(this.gKey,udata);
	            this.quoteUnique.changeWidth(udata);
	        }
	    },
	    forceUpdateUnqiueData:function(){// force update unqiue
	        if (this.option.hasUnqiue&&this.gKey!=null&&gData[this.gKey]){
	            var udata={};
	            //var marketQuoteData=push.proxy.getMarketQuoteData(this.gKey);
	            for(var field in this.quoteUnique.domMap){
					udata[field] = true;//QS_Formatter(this.gKey,[field],this.quoteUnique.dpfMap[field]);//data[field];
//	                udata[field] = marketQuoteData[field] ? marketQuoteData[field] : {
//	                    value: gData[this.gKey][field]
//	                };
	            }
	            this.quoteUnique.updateData(this.gKey,udata);
	            this.quoteUnique.changeWidth(udata);
	        }
	    },
	    _judgeUnqiueWidth:function(){
	        
	    },
	    saveConfig:function(){
	        return {
	            sequence:this.sequence
	        }
	    },
	    clear:function(){
	        if(this.option.showHead){
	            this.head.clear();
	        }
	        if (this.option.hasUnqiue){
	            this.quoteUnique.clear();
	        }
	        this.sequence=[];
	        for(var p in this){
	            if(!p || p == 'clear'){continue;}
	            this[p] = null;
	            delete this[p];
	        }
	    }
	};
